#include "stdafx.h"
#include "Log.h"

namespace Cvekas {

std::vector<LogListenerPtr> Log::listeners;
std::vector<LogListenerPtr>::iterator Log::itr;

void Log::init()
{
}

void Log::release()
{
	for(itr = listeners.begin(); itr != listeners.end(); ++itr)
		(*itr)->remove();

	listeners.clear();
}

void Log::log(const std::string& msg, const std::string& file, int line)
{
	const std::string m = FORMAT("%s:%d: %s", % file % line % msg); 
	for(itr = listeners.begin(); itr != listeners.end(); ++itr)
		(*itr)->sendMsg(m);
}

void Log::addListener(LogListenerPtr listener)
{
	listeners.push_back(listener);
	listener->add();
}

void Log::removeListener(LogListenerPtr listener)
{
	listener->remove();
	listeners.erase(remove(listeners.begin(), listeners.end(), listener));
}

} // namespace










